package Arrays;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class _217_ContainsDuplicate {
    public boolean containsDuplicate(int[] nums) {
        Set<Integer> singleSet = new HashSet<Integer>();
        for(int i=0;i<nums.length;i++) {
            if (singleSet.contains(nums[i])) {
                return true;
            }else{
                singleSet.add(nums[i]);
            }
        }
        return false;
    }

    //solution 2 use array.sort
    public boolean containsDuplicate1(int[] nums) {
        Arrays.sort(nums);
        for(int i=0;i<nums.length-1;i++) {
            if (nums[i] == nums[i + 1]) {
                return true;
            }
        }
        return false;
    }
}
